from db_init import db

class User(db.Model):
    id = db.Column(db.Integer,primary_key = True)
    name = db.Column(db.String(16))
    mobile = db.Column(db.String(11))
    order_id = db.relationship('Order',uselist=False)

class Order(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    number = db.Column(db.Integer)
    price = db.Column(db.Integer)
    start_time = db.Column(db.Integer)
    end_time = db.Column(db.Integer)
    user = db.relationship('User')
    user_id = db.Column(db.Integer,db.ForeignKey('user.id'))

room_facility = db.Table(
    'room_facility',
    db.Column('room_id',db.ForeignKey('room.id'), primary_key=True),
    db.Column('facility_id',db.ForeignKey('facility.id'), primary_key=True)
)

class Room(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    num = db.Column(db.Integer)
    status = db.Column(db.Enum(
        '空闲',
        '已预定',
        '已入住',
        '正在打扫',
    ),default='空闲')
    order_id = db.Column(db.Integer,db.ForeignKey('order.id'))
    order = db.relationship('Order')

# 设施
class Facility(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(16))
    icon = db.Column(db.String(2048))
    centent = db.Column(db.String(16))
    room_id = db.relationship('Room',secondary=room_facility,backref='facility',)

# 广告
class Advert(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    img = db.Column(db.String(2048))
    name = db.Column(db.String(16))
    url = db.Column(db.String(2048))
    room_id = db.Column(db.ForeignKey('room.id'))
